package io.renren.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.entity.ParticipantEntity;
import io.renren.service.ParticipantService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.ParticipantEntity;
import io.renren.service.ParticipantService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 与会人
 *
 * @author 1
 * @email 1@2.com
 * @date 2021-09-16 23:31:36
 */
@RestController
@RequestMapping("/participant")
public class ParticipantController {
    @Autowired
    private ParticipantService participantService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = participantService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions(":participant:info")
    public R info(@PathVariable("id") Long id){
        ParticipantEntity participant = participantService.getById(id);

        return R.ok().put("participant", participant);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions(":participant:save")
    public R save(@RequestBody ParticipantEntity participant){
        participantService.save(participant);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions(":participant:update")
    public R update(@RequestBody ParticipantEntity participant){
        ValidatorUtils.validateEntity(participant);
        participantService.updateById(participant);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions(":participant:delete")
    public R delete(@RequestBody Long[] ids){
        participantService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
